package com.neusmart.tongrentang.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;


import com.neusmart.tongrentang.R;

import java.util.List;

/**
 * Guide Adapter
 * <p/>
 * keven
 */
public class GuideAdapter extends PagerAdapter {

    private List<View> views;
    private View.OnClickListener l;

    public GuideAdapter(List<View> views, View.OnClickListener l) {
        this.views = views;
        this.l = l;
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView(views.get(position));
    }

    @Override
    public int getCount() {
        return views == null ? 0 : views.size();
    }

    @Override
    public Object instantiateItem(View container, int position) {
        ((ViewPager) container).addView(views.get(position));
        if (position == views.size() - 1) {
            views.get(position).findViewById(R.id.guide_btn_enter_app).setOnClickListener(l);
        }
        return views.get(position);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }
}
